import sys
import play
import datetime
import os

today = datetime.date.today()
os.chdir(os.path.dirname(__file__))
index = 0
if sys.platform == 'linux' and os.path.exists(f'apnews/{today.strftime("%m-%d.pdf")}'):
    exit()

if len(sys.argv) > 1:
    index = int(sys.argv[1])
    
pdf_file = play.pull_passage(False,index=index)
if sys.platform == 'linux':
    today = datetime.date.today()
    # if today.weekday() == 0:
    #     last = today - datetime.timedelta(days=3)
    # else:
    last = today - datetime.timedelta(days=1)
    last = last.strftime('%m-%d.pdf')
    os.system(f'test -e apnews/{last} && rm apnews/{last}')
    exit(0)
